import axios from "axios";

axios.defaults.headers["Content-Type"] =
  "application/x-www-form-urlencoded;charset=utf-8";

const instance = axios.create({
  baseURL: import.meta.env.VITE_BASE_API,
  timeout: 30000,
});

// 添加请求拦截器
instance.interceptors.request.use(
  function (config) {
    // let { token } = localStorage.getItem("user")
    //   ? JSON.parse(localStorage.getItem("user"))
    //   : { token: "" };
    // token = `Bearer ${token}`;

    // config.headers["Authorization"] = token;

    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

// 添加响应拦截器
instance.interceptors.response.use(
  function (response) {
    return response.data;
  },
  function (error) {
    return Promise.reject(error);
  }
);

export default instance;
